function spine_sorter

fnames={'C:\Users\georg\Desktop\awake_structural_stacks\exp16160_mean_data.tif'...
    'C:\Users\georg\Desktop\awake_structural_stacks\exp16169_mean_data.tif'...
    'C:\Users\georg\Desktop\awake_structural_stacks\exp16179_mean_data.tif'...
    'C:\Users\georg\Desktop\awake_structural_stacks\exp16187_mean_data.tif'};


for ind=1:4
    data{ind}=load_tiff(fnames{ind});
end

params.curr_ind=1;
params.frame_offset=zeros(4,1);

hf2001=figure(2001);
clf;
colormap gray

for ind=1:4
    ha2001(ind)=axes('position',[(ind-1)/4 0 1/4 1]);
    imagesc(data{ind}(:,:,params.curr_ind));
end
set(hf2001,'menubar','none','keypressfcn',{@spine_sorter_kpf,data,ha2001,hf2001})
set(hf2001,'userdata',params);

function spine_sorter_kpf(hf,event,data,ha2001,hf2001)
params=get(hf2001,'userdata');

fig_size=get(hf2001,'position');
fig_size=fig_size(3);
curr_point=get(hf2001,'currentpoint');
curr_point=curr_point(1);
curr_win=ceil(4*curr_point/fig_size);

switch event.Key
    case 'rightarrow'
        if strcmp(event.Modifier,'shift')
            params.frame_offset(curr_win)=params.frame_offset(curr_win)+1;
        else
            params.curr_ind=params.curr_ind+1;
        end
    case 'leftarrow'
        if strcmp(event.Modifier,'shift')
            params.frame_offset(curr_win)=params.frame_offset(curr_win)-1;
        else
            params.curr_ind=params.curr_ind-1;
        end
end
for ind=1:4
    axes(ha2001(ind));
    imagesc(data{ind}(:,:,params.curr_ind+params.frame_offset(ind)));
end
set(hf2001,'userdata',params);